package com.林子祺.CAT旅游系统.view.tour.admin;

import com.林子祺.CAT旅游系统.controller.contentmanagement.Admin;
import com.林子祺.CAT旅游系统.entity.place.CurrentPlaceData;
import com.林子祺.CAT旅游系统.entity.place.PlaceData;
import com.林子祺.CAT旅游系统.entity.ticket.CurrentTicketData;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class AddTicket {

    public static void update(){
        JFrame jf = new JFrame("门票改变");
        jf.setSize(550, 400);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        // 创建内容面板，使用边界布局
        JPanel panel = new JPanel(new BorderLayout());

        // 表头（列名）
        Object[] columnNames = {"景点id", "时间", "价格", "剩余门票"};

        // 表格所有行数据
        Object[][] rowData = {
                {"景点id", "时间", "价格", "剩余门票"},
                {null,null,null,null}
        };

        // 创建一个表格，指定 所有行数据 和 表头
        JTable table = new JTable(rowData, columnNames);

        // 把 表头 添加到容器顶部（使用普通的中间容器添加表格时，表头 和 内容 需要分开添加）
        panel.add(table.getTableHeader(), BorderLayout.NORTH);
        // 把 表格内容 添加到容器中心
        panel.add(table, BorderLayout.NORTH);

        JButton btn2 = new JButton("添加");
        panel.add(btn2, BorderLayout.WEST);
        btn2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String s = (String) table.getModel().getValueAt(1, 0);
                int MyInt1 = Integer.parseInt(s);
                CurrentTicketData.Place_id = MyInt1;

                CurrentTicketData.Time = (String) table.getModel().getValueAt(1, 1);

                String s1 = (String) table.getModel().getValueAt(1, 2);
                double MyInt = Double.parseDouble(s1);
                CurrentTicketData.cost = MyInt;

                String s2 = (String) table.getModel().getValueAt(1, 3);
                int MyInt2 = Integer.parseInt(s2);
                CurrentTicketData.left = MyInt2;

                Admin.AddTicket(CurrentTicketData.Place_id,CurrentTicketData.Time,CurrentTicketData.cost,CurrentTicketData.left);
                jf.dispose();
            }
        });

        JButton btn3 = new JButton("返回");
        panel.add(btn3, BorderLayout.EAST);
        btn3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                AdminMenu.menu();
                jf.dispose();
            }
        });

        jf.setContentPane(panel);
        jf.pack();
        jf.setLocationRelativeTo(null);
        jf.setVisible(true);

    }

}
